<#assign ctx=springMacroRequestContext.contextPath />
<#include "/macro/publicMacro.ftl">
<#import "/macro/Dialog.ftl" as Dialog>

<@header title="用户角色授权">

</@header>

<@body>
    <h2 class="module-title">用户角色授权</h2>

    <div class="alert alert-primary" role="alert">
        <nav class="nav">
            <#--<button class="btn btn-info" onclick="javascript: history.back(-1);return false;">返回</button>-->
            <a class="btn btn-info btn-sm" href="${ctx}/user/list" role="button" aria-pressed="true" style="height: 35px; margin-top: 20px">返回</a>

            <span style="margin-right: 50px; margin-left: 50px">用户别称<h4>${user.nickName}</h4></span>
            <span style="margin-right: 50px">用户名称<h3>${user.userName}</h3></span>
            <span style="margin-right: 50px">用户邮箱<h3>${user.maskEmail}</h3></span>
            <span style="margin-right: 50px" >用户手机号<h3>${user.maskPhone}</h3></span>
        </nav>
    </div>

    <div class="alert alert-info" role="alert">
        <form id="userAuthorizeForm">
        <ul class="list-group">
            <#list roleList as role>
                <li class="list-group-item">
                    <div class="form-check form-check-inline">
                        <input type="checkbox" class="form-check-input" name="roles" id="role${role.id}" value="${role.id}" <#if roleMap["${role.id}"]??>checked</#if>/>
                        <label class="form-check-label" for="role${role.id}">${role.name}</label>
                    </div>
                </li>
            </#list>

            <li class="list-group-item">
                <button type="submit" class="btn btn-primary" onclick="saveRoles(${user.id}); return false">保存</button>
            </li>
        </ul>
        </form>
    </div>

    <@Dialog.Dialog id="userAuthorizeDialog" title="用户角色授权">
    </@Dialog.Dialog>
</@body>

<@footer>
    <script>
        function saveRoles(id) {
            $.ajax({
                url:"${ctx}/manager/userAuthorize/save/json/" + id, //请求的url地址
                dataType:"json", //返回格式为json
                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                data: $("#userAuthorizeForm").serialize(),
                type:"post", //请求方式
                beforeSend:function(){
                    //请求前的处理
                },
                success:function(req){
                    $("#userAuthorizeDialog .modal-body").text("");
                    if (req.isSuccess) {
                        $("#userAuthorizeDialog .modal-body").text("保存成功");
                        $('#userAuthorizeDialog').modal({backdrop: 'static', keyboard: false})
                    } else {
                        $("#userAuthorizeDialog .modal-body").text("保存成功");
                        $('#userAuthorizeDialog').modal({backdrop: 'static', keyboard: false})
                    }
                },
                complete:function(){
                    //请求完成的处理
                },
                error:function(){
                    $("#userAuthorizeDialog .modal-body").text("请求失败");
                    $('#userAuthorizeDialog').modal({backdrop: 'static', keyboard: false});
                }
            });
        }
    </script>
</@footer>